package com.cn.esermis.netty;


import com.cn.esermis.model.BootNettyChannel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class BootNettyChannelCache {
    //保证可先性。adj.易变的，动荡不定的，反复无常的；（情绪）易变的，易怒的，突然发作的；
    public static volatile Map<String, BootNettyChannel> channelMapCache = new ConcurrentHashMap<String, BootNettyChannel>();

    //增加
    public static void add(String code, BootNettyChannel channel) {
        channelMapCache.put(code, channel);
    }

    //获取
    public static BootNettyChannel get(String code) {
        return channelMapCache.get(code);
    }

    //移除
    public static void remove(String code) {
        channelMapCache.remove(code);
    }

    //保存：如果不存在，才保存
    public static void save(String code, BootNettyChannel channel) {
        if (channelMapCache.get(code) == null) {
            add(code, channel);
        }
    }
}
